@extends('layout.master')

@section('title','商户vip设定')

@section('css')
    @parent
    <!-- Daterange picker plugins css -->
    <link href="{{ asset('plugins/bower_components/bootstrap-daterangepicker/daterangepicker.css') }}" rel="stylesheet">
    <style>
        .floating-labels .radioInput label {
            position: static;
        }

    </style>
@endsection
@section('main')
    <!-- form itself -->
    <form id="test-form" class="mfp-hide white-popup-block floating-labels vip-publish">
        <h3>添加VIP级别</h3>
        <hr>
        <div class="row">
            <div class="form-group m-b-40 m-t-10 col-md-3">
                <input type="text" class="form-control" id="title-publish" name="title" required><span
                        class="highlight"></span> <span class="bar"></span>
                <label for="title-publish">名称</label>
            </div>
            <div class="form-group m-b-40 col-md-3">
                <input type="text" class="form-control" id="weight-publish" name="weight" required><span
                        class="highlight"></span> <span class="bar"></span>
                <label for="weight-publish">权重</label>
            </div>
            <div class="form-group m-b-40 col-md-3">
                <input type="text" class="form-control" id="timelimt-publish" name="timelimt" required><span
                        class="highlight"></span> <span class="bar"></span>
                <label for="timelimt-publish">VIP时限</label>
            </div>
            <div class="form-group m-b-40 col-md-3">
                <input type="text" class="form-control" id="docnum-publish" name="docnum" required><span
                        class="highlight"></span> <span class="bar"></span>
                <label for="docnum-publish">医生上限</label>
            </div>
            <div class="form-group m-b-40 col-md-3">
                <input type="text" class="form-control" id="shownum-publish" name="shownum" required><span
                        class="highlight"></span> <span class="bar"></span>
                <label for="shownum-publish">展示图上限</label>
            </div>
            <div class="form-group m-b-40 col-md-3">
                <input type="text" class="form-control" id="coupon-publish" name="coupon" required><span
                        class="highlight"></span> <span class="bar"></span>
                <label for="coupon-publish">优惠卷展示时限</label>
            </div>
            <div class="form-group m-b-40 col-md-3">
                <input type="text" class="form-control" id="keeptime-publish" name="keeptime" required><span
                        class="highlight"></span> <span class="bar"></span>
                <label for="keeptime-publish">聊天记录保存时限</label>
            </div>
            <div class="skin skin-flat col-md-6">
                <div class="form-group radioInput m-b-40">
                    <label>圈子权限</label>
                    <div class="radio-list">
                        @foreach(App\Vip::$CircleStatusDisplay as $key => $value)
                            <label for="flat-radio-{{ $key }}" class="p-l-20 radio-inline p-0">
                                <input type="radio" class="check radioCheck"
                                       name="circle" value="{{ $key }}"
                                       data-radio="iradio_flat-purple">
                                {{ $value }}
                            </label>
                        @endforeach
                    </div>
                </div>
            </div>
            <div class="skin skin-flat col-md-6">
                <div class="form-group radioInput m-b-40">
                    <label>用户信息权限</label>
                    <div class="radio-list">
                        @foreach(App\Vip::$ScanuserDisplay as $key => $value)
                            <label for="flat-radio-{{ $key }}" class="p-l-20 radio-inline p-0">
                                <input type="radio" class="check radioCheck"
                                       name="scanuser" value="{{ $key }}"
                                       data-radio="iradio_flat-purple">
                                {{ $value }}
                            </label>
                        @endforeach
                    </div>
                </div>
            </div>
            <div class="skin skin-flat col-md-6">
                <div class="form-group radioInput m-b-40">
                    <label>咨询权限</label>
                    <div class="radio-list">
                        @foreach(App\Vip::$ConsultTypeDisplay as $key => $value)
                            <label for="flat-radio-{{ $key }}" class="p-l-20 radio-inline p-0">
                                <input type="radio" class="check radioCheck"
                                       name="consulttype" value="{{ $key }}"
                                       data-radio="iradio_flat-purple">
                                {{ $value }}
                            </label>
                        @endforeach
                    </div>
                </div>
            </div>
            <div class="skin skin-flat col-md-6">
                <div class="form-group radioInput m-b-40">
                    <label>群发权限</label>
                    <div class="radio-list">
                        @foreach(App\Vip::$QunsendDisplay as $key => $value)
                            <label for="flat-radio-{{ $key }}" class="p-l-20 radio-inline p-0">
                                <input type="radio" class="check radioCheck"
                                       name="qunsend" value="{{ $key }}"
                                       data-radio="iradio_flat-purple">
                                {{ $value }}
                            </label>
                        @endforeach
                    </div>
                </div>
            </div>
            <div class="skin skin-flat col-md-6">
                <div class="form-group radioInput m-b-40">
                    <label>状态</label>
                    <div class="radio-list">
                        @foreach(App\Vip::$StatusDisplay as $key => $value)
                            <label for="flat-radio-{{ $key }}" class="p-l-20 radio-inline p-0">
                                <input type="radio" class="check radioCheck"
                                       name="status" value="{{ $key }}"
                                       data-radio="iradio_flat-purple">
                                {{ $value }}
                            </label>
                        @endforeach
                    </div>
                </div>
            </div>
        </div>
        <div class="form-actions">
            <div class="row">
                <div class="col-md-12">
                    <div class="row">
                        <div class="col-md-offset-3 col-md-9">
                            <button type="submit" class="btn btn-success"><i
                                        class="fa fa-check"></i> 保存
                                {!! csrf_field() !!}
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>


    <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel1">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="exampleModalLabel1">修改</h4>
                </div>
                <div class="modal-body">
                    <form class="floating-labels vip-modify">
                        <input id="id-modify" name="id" type="hidden" value="">
                        <fieldset style="border:0;">

                            <div class="row">
                                <div class="form-group m-b-40 m-t-10 col-md-3">
                                    <input type="text" class="form-control" id="title-modify" name="title"
                                           required><span
                                            class="highlight"></span> <span class="bar"></span>
                                    <label for="title-modify">名称</label>
                                </div>
                                <div class="form-group m-b-40 col-md-3">
                                    <input type="text" class="form-control" id="weight-modify" name="weight"
                                           required><span
                                            class="highlight"></span> <span class="bar"></span>
                                    <label for="weight-modify">权重</label>
                                </div>
                                <div class="form-group m-b-40 col-md-3">
                                    <input type="text" class="form-control" id="timelimt-modify" name="timelimt"
                                           required><span
                                            class="highlight"></span> <span class="bar"></span>
                                    <label for="timelimt-modify">VIP时限</label>
                                </div>
                                <div class="form-group m-b-40 col-md-3">
                                    <input type="text" class="form-control" id="docnum-modify" name="docnum"
                                           required><span
                                            class="highlight"></span> <span class="bar"></span>
                                    <label for="docnum-modify">医生上限</label>
                                </div>
                                <div class="form-group m-b-40 col-md-3">
                                    <input type="text" class="form-control" id="shownum-modify" name="shownum" required><span
                                            class="highlight"></span> <span class="bar"></span>
                                    <label for="shownum-modify">展示图上限</label>
                                </div>
                                <div class="form-group m-b-40 col-md-3">
                                    <input type="text" class="form-control" id="coupon-modify" name="coupon"
                                           required><span
                                            class="highlight"></span> <span class="bar"></span>
                                    <label for="coupon-modify">优惠卷展示时限</label>
                                </div>
                                <div class="form-group m-b-40 col-md-3">
                                    <input type="text" class="form-control" id="keeptime-modify" name="keeptime"
                                           required><span
                                            class="highlight"></span> <span class="bar"></span>
                                    <label for="keeptime-publish">聊天记录保存时限</label>
                                </div>
                                <div class="skin skin-flat col-md-6">
                                    <div class="form-group radioInput m-b-40">
                                        <label>圈子权限</label>
                                        <div class="radio-list">
                                            @foreach(App\Vip::$CircleStatusDisplay as $key => $value)
                                                <label for="circle-{{ $key }}" class="p-l-20 radio-inline p-0">
                                                    <input type="radio" class="check radioCheck" id="circle-{{ $key }}"
                                                           name="circle" value="{{ $key }}"
                                                           data-radio="iradio_flat-purple">
                                                    {{ $value }}
                                                </label>
                                            @endforeach
                                        </div>
                                    </div>
                                </div>
                                <div class="skin skin-flat col-md-6">
                                    <div class="form-group radioInput m-b-40">
                                        <label>用户信息权限</label>
                                        <div class="radio-list">
                                            @foreach(App\Vip::$ScanuserDisplay as $key => $value)
                                                <label for="flat-radio-{{ $key }}" class="p-l-20 radio-inline p-0">
                                                    <input type="radio" class="check radioCheck"
                                                           id="scanuser-{{ $key }}"
                                                           name="scanuser" value="{{ $key }}"
                                                           data-radio="iradio_flat-purple">
                                                    {{ $value }}
                                                </label>
                                            @endforeach
                                        </div>
                                    </div>
                                </div>
                                <div class="skin skin-flat col-md-6">
                                    <div class="form-group radioInput m-b-40">
                                        <label>咨询权限</label>
                                        <div class="radio-list">
                                            @foreach(App\Vip::$ConsultTypeDisplay as $key => $value)
                                                <label for="consulttype-{{ $key }}" class="p-l-20 radio-inline p-0">
                                                    <input type="radio" class="check radioCheck"
                                                           id="consulttype-{{ $key }}"
                                                           name="consulttype" value="{{ $key }}"
                                                           data-radio="iradio_flat-purple">
                                                    {{ $value }}
                                                </label>
                                            @endforeach
                                        </div>
                                    </div>
                                </div>
                                <div class="skin skin-flat col-md-6">
                                    <div class="form-group radioInput m-b-40">
                                        <label>群发权限</label>
                                        <div class="radio-list">
                                            @foreach(App\Vip::$QunsendDisplay as $key => $value)
                                                <label for="qunsend-{{ $key }}" class="p-l-20 radio-inline p-0">
                                                    <input type="radio" class="check radioCheck" id="qunsend-{{ $key }}"
                                                           name="qunsend" value="{{ $key }}"
                                                           data-radio="iradio_flat-purple">
                                                    {{ $value }}
                                                </label>
                                            @endforeach
                                        </div>
                                    </div>
                                </div>
                                <div class="skin skin-flat col-md-6">
                                    <div class="form-group radioInput m-b-40">
                                        <label>状态</label>
                                        <div class="radio-list">
                                            @foreach(App\Vip::$StatusDisplay as $key => $value)
                                                <label for="status-{{ $key }}" class="p-l-20 radio-inline p-0">
                                                    <input type="radio" class="check radioCheck" id="status-{{ $key }}"
                                                           name="status" value="{{ $key }}"
                                                           data-radio="iradio_flat-purple">
                                                    {{ $value }}
                                                </label>
                                            @endforeach
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="form-actions">
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="row">
                                            <div class="col-md-offset-3 col-md-9">
                                                <button type="button" class="btn btn-default" data-dismiss="modal">取消
                                                </button>
                                                {!! csrf_field() !!}
                                                <button type="submit" class="btn btn-success" id="btn-refuse"><i
                                                            class="fa fa-check"></i> 保存
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </fieldset>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <div class="white-box">
        <h3 class="box-title m-b-0">商户vip设定</h3>
        <div class="panel">
            <div class="panel-action" style="margin-top: -9px">
                <a class="popup-with-form btn fcbtn btn btn-outline btn-info btn-1c" href="#test-form">
                    <span>添加VIP级别</span>
                </a>
            </div>
        </div>
        <div class="table-responsive">
            <table id="example23"
                   class="display nowrap table table-striped table-bordered table-hover order-column my-table "
                   cellspacing="0" width="100%" data-url="{{ url(request()->getUri()) }}">
                <thead>
                <tr>
                    <th>名称</th>
                    <th>权重</th>
                    <th>圈子权限</th>
                    <th>用户信息权限</th>
                    <th>咨询权限</th>
                    <th>状态</th>
                    <th>群发权限</th>
                    <th>时限</th>
                    <th>医生上限</th>
                    <th>展示图上限</th>
                    <th>优惠卷展示时限</th>
                    <th>聊天记录保存时限</th>
                    <th>编辑</th>
                </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
    </div>
@endsection

@section('js')
    @parent
    <!-- Plugin JavaScript -->
    <script src="{{ asset('plugins/bower_components/moment/moment.js') }}"></script>
    <!-- Date range Plugin JavaScript -->
    <script src="{{ asset('plugins/bower_components/bootstrap-daterangepicker/daterangepicker.js') }}"></script>
    <script src="{{ asset('js/myself.js') }}"></script>
    <script>
        $('.vip-publish').submit(function (e) {
            e.preventDefault();
            swal({
                    title: "",
                    text: "确定添加么？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        type: "POST",
                        url: '/store/storeVip/publish',
                        data: $('.vip-publish').serialize(),// 你的formid
                        async: false,
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        error: function (e) {
                            if (e.readyState === 4 && e.status === 422) {
                                for (var i in e.responseJSON) {
                                    if (e.responseJSON[i] !== 'The given data was invalid.') {
                                        err = e.responseJSON[i];
                                        for (var j in err) {
                                            swal(err[j][0]);
                                        }
                                    }
                                }
                            }
                        },
                        success: function (data) {
                            if (data.status === 1) {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    location.reload();
                                });
                            } else {
                                swal(data.message);
                            }
                        }
                    })
                }
            );

        });


        function modify(sid) {
            $.ajax({
                type: "POST",
                url: '/store/storeVip/info/' + sid,
                async: false,
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                error: function (e) {
                    if (e.readyState === 4 && e.status === 422) {
                        for (var i in e.responseJSON) {
                            if (e.responseJSON[i] !== 'The given data was invalid.') {
                                err = e.responseJSON[i];
                                for (var j in err) {
                                    swal(err[j][0]);
                                }
                            }
                        }
                    }
                },
                success: function (data) {
                    $("#id-modify").val(data.id);
                    $("#title-modify").val(data.title);
                    $("#weight-modify").val(data.weight);
                    $("#timelimt-modify").val(data.timelimt);
                    $("#docnum-modify").val(data.docnum);
                    $("#shownum-modify").val(data.shownum);
                    $("#coupon-modify").val(data.coupon);
                    $("#keeptime-modify").val(data.keeptime);
                    $('.radioCheck').removeAttr('checked', true).parent().removeClass('checked');
                    $('#circle-' + data.circle).attr('checked', true).parent().addClass('checked');
                    $('#scanuser-' + data.scanuser).attr('checked', true).parent().addClass('checked');
                    $('#consulttype-' + data.consulttype).attr('checked', true).parent().addClass('checked');
                    $('#qunsend-' + data.qunsend).attr('checked', true).parent().addClass('checked');
                    $('#status-' + data.status).attr('checked', true).parent().addClass('checked');
                }
            })
        }

        $('.vip-modify').submit(function (e) {
            e.preventDefault();
            swal({
                    title: "",
                    text: "确定修改么？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        type: "POST",
                        url: '/store/storeVip/modify/' + $("#id-modify").val(),
                        data: $('.vip-modify').serialize(),// 你的formid
                        async: false,
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        error: function (e) {
                            if (e.readyState === 4 && e.status === 422) {
                                for (var i in e.responseJSON) {
                                    if (e.responseJSON[i] !== 'The given data was invalid.') {
                                        err = e.responseJSON[i];
                                        for (var j in err) {
                                            swal(err[j][0]);
                                        }
                                    }
                                }
                            }
                        },
                        success: function (data) {
                            if (data.status === 1) {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    location.reload();
                                });
                            } else {
                                swal(data.message);
                            }
                        }
                    })
                }
            );

        });

    </script>
@endsection